// 引入路由( vue-router 3.x.x版本   4.x.x以上不是这样创建的 )
import Vue from "vue"
import VueRouter from "vue-router"
Vue.use(VueRouter)

const Index = () => import("@/components/Index.vue")

// 创建路由器
const routes = [
    {
        path: "/",
        name: "home",
        meta: { title: "首页" },
        component: Index,
    },
    {
        path: "/changjing",
        name: "changjing",
        component: Index,
        children: [
            {
                path: "/xunigundong",
                name: "xunigundong",
                component: () => import("@/components/demo/XuNiGunDong/index.vue"),
                meta: { title: "虚拟滚动" },
            },
            {
                path: "/SvgDemo",
                name: "SvgDemo",
                component: () => import("@/components/demo/SvgDemo/index.vue"),
                meta: { title: "SVG封装" },
            },
        ],
    },
]

const router = new VueRouter({
    // mode: "history", // 路由模式
    scrollBehavior: () => ({ y: 0 }), // 滚动行为
    routes,
})


router.beforeEach((to, from, next) => {
    // 设置页面标题
    document.title = to.meta.title || "首页"
    next()
})
export default router
